package m3;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.util.Scanner;

public class Producer {
    public static void main(String[] args) throws Exception {
        // 连接
        ConnectionFactory f = new ConnectionFactory();
        f.setHost("192.168.64.140");
        f.setPort(5672);
        f.setUsername("admin");
        f.setPassword("admin");
        Connection conn = f.newConnection();
        Channel channel = conn.createChannel();// 使用这个通信通道进行通信

        // 定义交换机，命名为logs
        /*channel.exchangeDeclare("logs", "fanout");*/
        channel.exchangeDeclare("logs", BuiltinExchangeType.FANOUT);

        // 向logs交换机发送消息
        while (true) {
            System.out.print("输入： ");
            String msg = new Scanner(System.in).nextLine();
            // 第二个参数对 fanout交换机无效
            channel.basicPublish("logs", "", null, msg.getBytes());
        }


    }


}
